public class Solution {
    //反转二叉树
    public BinaryTree.TreeNode invertTree(BinaryTree.TreeNode root) {

        if (root == null) {

            return null;

        }

        //代码走到这说明二叉树不为空

        BinaryTree.TreeNode temp = null;

        temp = root.left;

        root.left = root.right;

        root.right = temp;

        invertTree(root.left);

        invertTree(root.right);

        return root;

    }

    //检查两颗二叉树是否相同
    public boolean isSameTree(BinaryTree.TreeNode p, BinaryTree.TreeNode q) {

        if ((p == null && q != null) || (p != null && q == null)) {

            return false;

        }

        //都为空

        if (p == null && q == null) {

            return true;

        }

        //都不为空

        //值不相等

        if (p.val != q.val) {

            return false;

        }

        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);

    }

//判断二叉树是否对称
    public boolean isSymmetric(BinaryTree.TreeNode root){
        //二叉树为空，也是对称二叉树
        if(root==null){
            return  true;
        }
        //二叉树不为空，看左树与右树是否对称
        return isSameTree1(root.left,root.right);

    }
    public  boolean  isSameTree1(BinaryTree.TreeNode leftTree, BinaryTree.TreeNode rightTree){
        if(leftTree==null&&rightTree!=null||leftTree!=null&&rightTree==null){
            return  false;
        }
        if(leftTree==null&&rightTree==null){
            return  true;
        }
        if(leftTree.val!=rightTree.val){
            return  false;
        }
        return isSameTree1(leftTree.left,rightTree.right)&&isSameTree1(leftTree.right,rightTree.left);
    }

    //另一棵树的子树
    public  boolean isSubtree(BinaryTree.TreeNode root, BinaryTree.TreeNode subRoot){
        if(root==null){
            return  false;
        }
        if(isSameTree(root,subRoot)){
            return true;
        }
        if(isSubtree(root.left,subRoot)){
            return true;
        }
        if(isSubtree(root.right,subRoot)){
            return true;
        }
        return false;
    }
}